package xin.marcher.module.search.message;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import xin.marcher.module.search.domain.dto.TableDataChangeDTO;
import xin.marcher.module.search.domain.entity.ProductSearchDO;
import xin.marcher.module.search.repository.ProductSearchRepository;

import java.io.IOException;
import java.util.List;

/**
 *
 */
@Component
public class ItemInfoTableMessageHandler implements MessageHandler {

    @Autowired
    private ProductSearchRepository productSearchRepository;

    @Override
    public String tableName() {
        return "item_info";
    }

    @Override
    public void handleMessage(TableDataChangeDTO tableDataChangeDTO) throws IOException {
        String itemId = String.valueOf(tableDataChangeDTO.getKeyId());
        List<ProductSearchDO> productSearchDOS = productSearchRepository.queryProductSearchInfos(itemId);
        productSearchRepository.saveProductSearchInfos(productSearchDOS);
    }
}
